package com.sk.sourcecircle.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.sk.sourcecircle.R;
import com.sk.sourcecircle.entity.GroupListBean;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by sk on 2017/12/20.
 */

public class SpinnerAdapter extends BaseAdapter {

    private List<GroupListBean.DataBean> dataBeans = new ArrayList<>();

    private Context context;

    public SpinnerAdapter(List<GroupListBean.DataBean> dataBeans, Context context) {
        this.dataBeans = dataBeans;
        this.context = context;
    }

    @Override
    public int getCount() {
        return dataBeans.size();
    }

    @Override
    public Object getItem(int position) {
        return dataBeans.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
       ViewHolder holder = null;
       if(convertView==null){
           holder = new ViewHolder();
           convertView = LayoutInflater.from(context).inflate(R.layout.item_spinner,parent,false);
           holder.textView = convertView.findViewById(R.id.tv_name);
           convertView.setTag(holder);
       }else {
           holder = (ViewHolder) convertView.getTag();
       }
       holder.textView.setText(dataBeans.get(position).getCommunity_name());
       return convertView;
    }

    class ViewHolder{
        TextView textView;
    }
}
